//
// Rectangle.hh for  in /home/gomes_m//workzone/test/gdl
// 
// Made by mickael gomes
// Login   <gomes_m@epitech.net>
// 
// Started on  Tue Apr 30 16:35:24 2013 mickael gomes
// Last update Thu May 23 14:09:31 2013 mickael gomes
//

#include	<cstdio>
#include	<cstdlib>
#include	<iostream>
#include	"Primitive.hh"

void Rectangle::initialize(std::string const &path, float x1, float y1, float x2, float y2, float z)
{
  std::cout << "Rectangle construit avec path ===> " << path << " " << std::endl;
  posx1_ = x1;
  posx2_ = x2;
  posy1_ = y1;
  posy2_ = y2;
  z_ = z;
  texture_ = gdl::Image::load(path);
  buffer.LoadFromFile("sound/Cursor.wav");
  x_ = 0;
}

void Rectangle::update(gdl::GameClock const & gameClock, gdl::Input & input)
{
  if (input.isKeyDown(gdl::Keys::Return) == true)
    {
      if (x_ == 0)
	std::cout << "New Game !" << std::endl;
      else
	std::cout << "Continue !" << std::endl;
    }
  if (input.isKeyDown(gdl::Keys::Up) == true)
    {
      sound.SetBuffer(buffer);
      sound.Play();
      if (x_ == 0)
	x_ = -110;
      else
	x_ += 110;
        std::cout << "poil" << std::endl;
    }
  if (input.isKeyDown(gdl::Keys::Down) == true)
    {
      sound.SetBuffer(buffer);
      sound.Play();
      if (x_ == -110)
	x_ = 0;
      else
	x_ -= 110;
      std::cout << "poil" << std::endl;
    }

}

void Rectangle::draw(void)
{
  ////////////////////////////////////////////////////////////////////////////////
  /// Ouverture d’un contexte de rendu
  ////////////////////////////////////////////////////////////////////////////////
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glBegin(GL_QUADS);
  ////////////////////////////////////////////////////////////////////////////////
  /// Configuration de la couleur des vertices
  ////////////////////////////////////////////////////////////////////////////////
  ////////////////////////////////////////////////////////////////////////////////
  /// Dessin des vertices
  ////////////////////////////////////////////////////////////////////////////////
  /// Vertex superieur gauche
  // glVertex3f(-350.0f, 100.0f, 0.0f);
  /// Vertex inferieur gauche
  // glVertex3f(-350.0f, -100.0f, 0.0f);
  /// Vertex inferieur droit
  // glVertex3f(-150.0f, -100.0f, 0.0f);
  /// Vertex superieur droit
  // glVertex3f(-150.0f, 100.0f, 0.0f);
  ////////////////////////////////////////////////////////////////////////////////
  /// Fermeture du contexte de rendu
  ////////////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////
  /// Dessin des vertices
  /////////////////////////////////////////
  /// Vertex superieur gauche
  glTexCoord2f(0.2f, 0.2f);
  glVertex3f(posx1_, posy1_ + x_, z_);
  // Vertex inferieur gauche
  glTexCoord2f(0.2f, 0.8f);
  glVertex3f(posx1_, posy2_ + x_, z_);
  // Vertex inferieur droit
  glTexCoord2f(0.8f, 0.8f);
  glVertex3f(posx2_, posy2_ + x_, z_);
  // Vertex superieur droit
  glTexCoord2f(0.8f, 0.2f);
  glVertex3f(posx2_, posy1_ + x_, z_);
  glEnd();
  glDisable(GL_BLEND);
}
